package gases.as3.librarys.components.ui.control.datagrid
{
	import flash.utils.Dictionary;
	
	import gases.as3.librarys.components.ui.GUIComponents;
	
	public class GridLine extends GUIComponents
	{
		public static const INIT_WIDTH:Number = 80;
		public static const INIT_HEIGHT:Number = 20;
		public static const INIT_COLOR:uint = 0x000000;
		/**
		 * 数据数组和宽度数组一一对应，宽度数组可以为空，高度可以为空
		 * @param dataArr 数据数组
		 * @param widthArr 宽度数组 ，宽度默认值每个都为80
		 * @param height 高度 默认值为20
		 * 
		 */		
		public function GridLine(dataArr:Array,colorArr:Array = null,widthArr:Array = null,height:Number = 20,canMouse:Boolean = true)
		{
			_dataArray =  		dataArr;
			_colorArr =  		colorArr;
			_widthArray = 		widthArr;
			_height = 			height;
			cellDict =			 new Dictionary();
			_canMouse = 		canMouse;
  			super();
		}
		
		override protected function initialization():void
		{
			if(_dataArray.length == 0)
			{
				throw new Error("当前加入单元行数据为空!");
			}
			if(_widthArray == null)
			{
				_widthArray = new Array();
			}
			if(_colorArr == null)
			{
				_colorArr = new Array();
			}
			var num_1:int = _dataArray.length - _widthArray.length;
			if(num_1 > 0)
			{
				for(var les_1:int = 0;les_1 < num_1;les_1++ )
				{
					_widthArray.push(INIT_WIDTH);
				}
			}
			
			var num_2:int = _dataArray.length - _colorArr.length;
			if(num_2 > 0)
			{
				for(var les_2:int = 0;les_2 < num_2;les_2++ )
				{
					_colorArr.push(INIT_COLOR);
				}
			}
			
			colNumber = _dataArray.length;
			for(var i:int = 0;i < colNumber;i++)
			{
				var cell:GridCell = new GridCell(_widthArray[i],_height);
				cell.setDataValue(_dataArray[i],_colorArr[i]);
				if(i == 0)
				{
					cell.x = 0;
					_prePostion = 0;
				}
				else
				{
					_prePostion +=  _widthArray[i - 1] as Number;
					cell.x = _prePostion;
				}
				
				this.addChild(cell);
				cellDict[i] = cell;
			}
			if(!_canMouse)
			{
				this.mouseChildren = false;
				this.mouseEnabled = false;
			}
		}
		
		override public function dispose():void
		{
			_prePostion = 0;
			_dataArray = null;
			_widthArray = null;
			_colorArr = null;
			cellDict = null;
			cellDict = new Dictionary;
			_height = 20;
			colNumber = 0;
			super.dispose();
		}
		
		public function lineOver():void
		{
			for each(var cell:GridCell in cellDict)
			{
				cell.cellOver();	
			}
		}
		
		public function lineOut():void
		{
			for each(var cell:GridCell in cellDict)
			{
				cell.cellOut();	
			}
		}
		
		public function lineClick():void
		{
			for each(var cell:GridCell in cellDict)
			{
				cell.cellClick();	
			}
		}
		
		public function get dataArray():Array
		{
			return _dataArray;
		}
		private var _prePostion:Number ;
		private var _dataArray:Array;
		private var _widthArray:Array;
		private var _colorArr:Array;
		private var _height:Number;
		private var _canMouse:Boolean = true;
		
		private var colNumber:int;
		
		private var cellDict:Dictionary ;
	}
}